/**
 * Created by zeopean on 2015/10/16.
 */
var page = 1 ;

$(function(){
    /** 初始化ajax */
    jQuery.ajaxSetup({
        case:false,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $(document).on('click' ,'.more_bar' , function(){
        var stop = true;
        if(stop==true){
            stop=false;

            $.ajax({
                type:"get",
                url:getProjectMore,
                dataType:"json",
                data:{'page':page},
                success:function(obj){
                    setTimeout(function(){
                        if (obj.level == "success") {
                            showProjectBySearch(obj.data);
                        }
                    },500);
                    stop = true;
                    page = page + 1;
                }
            });
        }
    });





});


function showProjectBySearch(projects) {
    var HtmlAll='';
    for (var i = 0; i < projects.length; i++) {
        if (projects[i] !== 'undefined') {
            var phase = '';
            if(projects[i]['phase']){
                phase = projects[i]['phase']['phase'];
            }
            if(!projects[i]['project_intro']){
                projects[i]['project_intro'] = '';
            }
            var HTMLInitData = '<li><dl><dt><a href="' + projects[i].id + '"><img src="' + showLogo + projects[i].id + '"/></a></dt>' +
                '<dd class="commpany">' +
                '<p><a href="' + projectUrl + projects[i]['id'] + '"><strong>' + projects[i]['project_name'] + '</strong></a></p>' +
                '<p>' + projects[i]['project_intro'] + '</p>' +
                '</dd>' +
                '<dd class="list"><div class="list_content"><p class="stage"><em class="reveal">融资阶段</em>'+
                '<em class="floatR">' + phase + '</em></p>'+
                '<p class="type"><em class="reveal">所在行业</em>';
            var fields = '';
            for(var m in projects[i]['fields']) {
                fields = fields +  '<em class="floatR">' + projects[i]['fields'][m].field + '</em>';
            }
            var district =   '</p>'+
                '<p class="address"><em class="reveal">所在地区</em>'+
                '<em class="floatR">' + projects[i]['province'] + projects[i]['city'] + '</em></p><p class="member">';

            var teams = '';
            for(var n in projects[i]['teams']){
                teams = teams + '<em class="reveal">' + projects[i]['teams'][n].real_name + '</em>';
            }

            var footer =  '</p></div></dd></dl></li>';
            HTMLInitData = HTMLInitData + fields + district + teams + footer;

        }
        HtmlAll += HTMLInitData;
    }
    var onceStr = $(".content ul").html();
    $(".content ul").html(onceStr+HtmlAll);
}

function init(){}